<%@page import="java.util.TreeMap"%>
<%@page import="models.User"%>
<%@page import="models.Blog"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="net.tanesha.recaptcha.ReCaptchaFactory"%>
<%@page import="net.tanesha.recaptcha.ReCaptcha"%>
<%
String success = (String) request.getAttribute("success");
String error = (String) request.getAttribute("error");
ArrayList<Blog> blogs = (ArrayList<Blog>) request.getAttribute("blogs");
ArrayList<User> users = (ArrayList<User>) request.getAttribute("users");
User user = (User) request.getAttribute("user");
TreeMap check = (TreeMap) request.getAttribute("check");
String form = (String) request.getAttribute("form");
%>

<jsp:include page="/layouts/header.jsp">
	<jsp:param name="title" value="" />
	<jsp:param name="description" value="" />
	<jsp:param name="keywords" value="" />
	<jsp:param name="page" value="home" />
</jsp:include>

<div id="userform" class="clearafter">
	<h1><%=form.equalsIgnoreCase("edit") ? "View profile" : "Add User" %></h1><hr/>
	<div class="submitlink">
		<%=success!=null?"<p style='color:blue'>"+success+"</p>":"" %>
		<%=error!=null?"<p style='color:red'>"+error+"</p>":"" %>
		<form method="post" action="" name="signupform">
			<p>
				<label> Username <br /> 
				<% if (check.get("gmail") != null) { %>
					<span class="error"><%=check.get("gmail")%></span><br />
				<% } %>
				<% if (form != null && form.equalsIgnoreCase("edit")) { %>
				<b class="font-24"><%=user.getGmail() %></b>
				<% }  else { %>
				<input class="input" type="text" name="gmail" value=""/>
				<% } %>
				</label>
			</p>
			<p>
				<label> Role <br /> </label>
				User <input class="input type" type="radio"
					name="role"  style="width: auto;"  value="0" 
					<%=form != null && form.equalsIgnoreCase("edit")? "disabled=\"disabled\"" : ""%>
					<%=user.getRole() == 0 ? "checked=\"checked\"" : "" %>/>&nbsp;&nbsp;&nbsp;&nbsp;
				Administrator <input class="input type" type="radio"
					name="role"  style="width: auto;" value="1" 
					<%=form != null && form.equalsIgnoreCase("edit")? "disabled=\"disabled\"" : ""%>
					<%=user.getRole() == 1 ? "checked=\"checked\"" : "" %>/>
			</p>
			<p>
				<label> 
					Fullname <br /> 
					<% if (check.get("fullname") != null) { %>
						<span class="error"><%=check.get("fullname")%></span><br />
					<% } %>
					<input class="input" type="text" name="fullname"  value="<%=user.getName()%>"/> 
				</label>
			</p>
			<p>
				<label> Status <br />
					<select name="status" class="input type" <%=form != null && form.equalsIgnoreCase("edit") ? "disabled=\"disabled\"" : "" %>>
						<option value="0" <%=user.getStatus()==0 ? "selected=\"selected\"" : "" %>>Inactive</option>
						<option value="1" <%=user.getStatus()==1 ? "selected=\"selected\"" : "" %>>Pending</option>
						<option value="2" <%=user.getStatus()==2 ? "selected=\"selected\"" : "" %>>Active</option>
					</select>
				</label>
			</p>
			<p>
				<label> 
					Maximum blogs:
					<img class="question" src="/images/i-help.gif" alt="Question">
					<span class="note">Maximum blog for a user.</span> <br /> 
					<% if (check.get("limitBlog") != null) { %>
						<span class="error"><%=check.get("limitBlog")%></span><br />
					<% } %>
					<b class="font-24"><%=user.getLimitBlog()%></b>
					<input class="input" type="hidden" name="limitBlog"  value="<%=user.getLimitBlog()%>"/> 
				</label>
			</p>
			<% if (form != null && form.equalsIgnoreCase("edit")) { %>
			<p>
				<label>Created <br />
				<b class="font-24"><%=user.getCreated() %></b>
				</label>
			</p>
			<p>
				<label>Expired <br />
				<b class="font-24"><%=user.getExpired() %></b>
				</label>
			</p>
			<% } %>
			<div id='load-field'>
				
			</div>
			<p>
				<br />
				<input type="submit" value="<%=form != null && form.equalsIgnoreCase("edit") ? "Update" : "Submit" %>" />
			</p>
		</form>
	</div>
	<div class="howdy">
		<h2 class="title">Hi, <%=user.getName() %> </h2>
		<ul class="option">
			<li><a href="/add-blog">Add blog</a></li>
			<li><a href="/view-profile">View profile</a></li>
			<li><a href="/logout">Logout</a></li> 
		</ul>
		
		<% if (form.equalsIgnoreCase("edit")) { %>
		<h2 class="title" style="padding-top: 20px;">List blogs</h2>
		<div class="listlink">
			<ul>
				<% for(int i = 0 ; i < blogs.size(); i++) { %>
				<li><a class="<%=blogs.get(i).getType() != null && blogs.get(i).getType().equalsIgnoreCase("wordpress") ? "icon-wordpress" : "icon-blogger" %><%=blogs.get(i).getStatus()==0 ? " inactive" : "" %>"
						href="/edit-blog/<%=blogs.get(i).getBlogId()%>"><%=blogs.get(i).getBlogName() %> (<%=blogs.get(i).getBlogId()%>)</a></li>
				<% } %>
			</ul>
		</div>
		<% } else { %>
		<h2 class="title" style="padding-top: 20px;">List user</h2>
		<div class="listlink">
			<ul>
				<% for(int i = 0 ; i < users.size(); i++) { %>
				<li> - <a href="/view-profile/<%=users.get(i).getGmail()%>"><%=users.get(i).getGmail() %></a></li>
				<% } %>
			</ul>
		</div>
		<% } %>
	</div>
</div>
<%@ include file='/layouts/footer.jsp'%>